﻿
'Description:检测项业务类接口
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:Yangsj
'create Date:2017-4-19
'Rewriter:
'Rewrite Date:
Imports BusinessRule.DTO
Imports BusinessRule.IBusiness
Imports DatabaseAccess.DBUtility
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.Data
Imports System.Text
Imports System.Data.OracleClient
Imports BusinessRule.Common
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Net

Public Class uLMSStepCheckPointBusiness
    Implements uLMSStepCheckPointIBusiness

    ''' <summary>
    ''' 获取检测项列表
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetStepCheckPointList(ByVal para As System.Collections.Generic.Dictionary(Of String, String)) As DTO.uMESProcessResult Implements IBusiness.uLMSStepCheckPointIBusiness.GetStepCheckPointList
        GetStepCheckPointList = New uMESProcessResult
        Dim HasStepinfo As Boolean = para.ContainsKey("StepinfoID")
        Dim sb As New StringBuilder
        sb.AppendLine("SELECT SC.NAME,SC.CHECKNO,SC.PRODUCTID,SC.WORKFLOWSTEPID,WFS.WORKFLOWSTEPNAME,SC.INPUTNUM,SC.CHECKPOINTNOTE,")
        sb.AppendLine("SC.CHECKINPUTTYPE,DECODE(SC.CHECKINPUTTYPE, '1', '标准', '2', '临时', CHECKINPUTTYPE) CHECKINPUTTYPENAME,")
        sb.AppendLine("SC.CHECKTYPE,DECODE(SC.CHECKTYPE, '3', '设计特性', '4', '过程参数','5','振动攻关',CHECKTYPE) CHECKTYPENAME,")
        sb.AppendLine("SC.KEYCHECK,DECODE(SC.KEYCHECK, '1', '是', '0', '否', KEYCHECK) KEYCHECKNAME,")
        sb.AppendLine("SC.MEOPCHECK,DECODE(SC.MEOPCHECK, '1', '是', '0', '否', MEOPCHECK) MEOPCHECKNAME,")
        sb.AppendLine("SC.QUALITYCHECK, DECODE(SC.QUALITYCHECK, '1', '是', '0', '否', QUALITYCHECK) QUALITYCHECKNAME,")
        sb.AppendLine("DECODE(SC.TCCHECKPOINTNOTE, NULL, '否', '是') ISTCM,sc.checkpointnotedis,sc.DrawingRequireDis,")
        sb.AppendLine("BaseValue,CeilFloat,FloorFloat,BubbleNumber,SC.CHECKREQUIRE,") 'yuxj增加基准值，上下公差，气泡号
        sb.AppendLine("decode(ISCOMPP,1,'是','否') ISCOMPP,decode(ISDISASSEMBLE,1,'是','否') ISDISASSEMBLE,decode(ISINSTALL,1,'是','否') ISINSTALL,decode(ISNOTICE,1,'是','否') ISNOTICE,decode(ISRETURN,1,'是','否') ISRETURN, ") 'add by longb 2023-03-13
        If HasStepinfo Or para.ContainsKey("StepInfoCheckPoint") Then
            sb.AppendLine(" SO.STEPSEQ,sc.StepinfoID,sob.STEPINFONAME,so.stepno||'-'||so.description stepinfodesc,ST.SPECTYPENAME,DECODE( COUNT(scr.WorkerID),0,'未录','已录') status,DECODE( COUNT(scr.checkerid),0,'未录','已录') checkstatus,COUNT(scr.WorkerID) AINPUTNUM,COUNT(scr.checkerid) CINPUTNUM,") 'modify by longb 2022-12-26 新增检验员录入状态
        End If
        sb.AppendLine("SC.INTIME,SC.STEPCHECKPOINTID,SC.drawingrequire,SC.ASSEMBLYTYPE")
        sb.AppendLine(",sc.BASEVALUE,sc.FLOORFLOAT,sc.CEILFLOAT,decode(sc.SPCTYPE,'1','计数型','2','计量型','') SPCTYPE,sc.SPCRULE,DECODE(sc.ISSPC,'1','是','否') ISSPC,SC.CHECKMETHOD") 'add by longb 2023-02-22
        sb.AppendLine("  FROM STEPCHECKPOINT SC")
        'sb.AppendLine(" INNER JOIN PRODUCT P  ON P.PRODUCTID = SC.PRODUCTID") 'Modify YangJiang 20180608 取消按件号查询
        'sb.AppendLine(" INNER JOIN PRODUCTBASE PB  ON P.PRODUCTBASEID = PB.PRODUCTBASEID ")
        sb.AppendLine(" INNER JOIN WORKFLOWSTEP WFS ON SC.WORKFLOWSTEPID=WFS.WORKFLOWSTEPID")
        If HasStepinfo Or para.ContainsKey("StepInfoCheckPoint") Then
            sb.AppendLine(" LEFT JOIN STEPINFO SO on so.WORKFLOWSTEPID = sc.WORKFLOWSTEPID and so.stepinfoid=sc.stepinfoid  ")
            sb.AppendLine("left join STEPINFOBASE SOB ON SO.STEPINFOBASEID = SOB.STEPINFOBASEID") 'modify tianFW SO.STEPINFOID = SOB.REVOFRCDID->SO.STEPINFOBASEID = SOB.STEPINFOBASEID 2018年4月23日
            sb.AppendLine("LEFT JOIN SPECTYPE ST ON ST.SPECTYPEID = SO.SPECTYPEID")
            sb.AppendLine("LEFT JOIN stepcheckpointresult scr ON scr.stepcheckpointid=sc.stepcheckpointid") 'add yangJiang 20180731
            If para.ContainsKey("ContainerID") Then
                sb.AppendFormat(" and scr.containerid='{0}'", para("ContainerID")) 'Modify by Yuxj20180907
            End If
        End If
        'Modify YangJiang 20180608 取消按件号查询
        'If para.ContainsKey("ProductID") Then
        '    sb.AppendFormat(" AND SC.PRODUCTID='{0}' ", para("ProductID"))
        'ElseIf para.ContainsKey("ProductName") And para.ContainsKey("ProductRev") Then
        '    sb.AppendFormat(" AND PB.PRODUCTNAME='{0}' AND P.PRODUCTREVISION='{1}' ", para("ProductName"), para("ProductRev"))
        'End If
        sb.AppendLine(" WHERE 1=1")
        If para.ContainsKey("StepID") Then
            sb.AppendFormat(" AND SC.WORKFLOWSTEPID = '{0}' ", para("StepID"))
        End If

        'add by Yuxj 添加工步
        If HasStepinfo Then
            If Not String.IsNullOrWhiteSpace(para("StepinfoID")) Then
                sb.AppendFormat(" AND SO.StepinfoID = '{0}' ", para("StepinfoID"))
            End If
        End If

        If para.Keys.Contains("WorkflowID") Then 'add tianFW 根据wrokflowID全部显示工序检测项2017/10/25
            sb.AppendFormat(" AND WFS.WORKFLOWID='{0}'", para("WorkflowID"))
        End If
        'add yangJiang 20180731
        sb.AppendLine(" GROUP BY SC.NAME,SC.CHECKNO,SC.PRODUCTID,SC.WORKFLOWSTEPID,WFS.WORKFLOWSTEPNAME,SC.INPUTNUM,SC.CHECKPOINTNOTE,sc.BASEVALUE,sc.FLOORFLOAT,sc.CEILFLOAT,sc.SPCTYPE,sc.SPCRULE,sc.ISSPC,") 'modify by longb 2023-02-22
        sb.AppendLine("SC.CHECKINPUTTYPE,SC.CHECKINPUTTYPE,SC.CHECKTYPE,SC.CHECKTYPE,SC.KEYCHECK,SC.KEYCHECK,SC.MEOPCHECK,SC.MEOPCHECK,")
        sb.AppendLine("SC.QUALITYCHECK,SC.QUALITYCHECK,SC.TCCHECKPOINTNOTE,SC.INTIME,SC.STEPCHECKPOINTID,SC.drawingrequire,SC.ASSEMBLYTYPE,sc.checkpointnotedis,sc.DrawingRequireDis,")
        sb.AppendLine("BaseValue,CeilFloat,FloorFloat,BubbleNumber,SC.CHECKREQUIRE") 'yuxj增加基准值，上下公差，气泡号
        sb.AppendLine(",ISCOMPP, ISDISASSEMBLE, ISINSTALL, ISNOTICE, ISRETURN,WFS.SEQUENCE,SC.CHECKMETHOD")
        If HasStepinfo Or para.ContainsKey("StepInfoCheckPoint") Then
            sb.AppendLine(" ,sc.StepinfoID,sob.STEPINFONAME,SO.STEPNO||'-'||so.description,ST.SPECTYPENAME,SO.STEPSEQ,SO.STEPNO")
        End If
        If para.ContainsKey("StepInfoCheckPoint") Then 'Add ORDER BY WFS.SEQUENCE,SO.STEPNO by tianFW 2018年4月23日
            sb.AppendLine("ORDER BY WFS.SEQUENCE,SO.STEPNO,SO.STEPSEQ,SC.CHECKNO")
        Else
            sb.AppendLine("ORDER BY  WFS.SEQUENCE,SC.CHECKNO")
        End If
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sb.ToString)

        If dt Is Nothing Then
            GetStepCheckPointList.Result = False
        Else
            GetStepCheckPointList.Result = True
            GetStepCheckPointList.DBTable = dt
        End If
    End Function

    ''' <summary>
    ''' Add by Yuxj20181010
    ''' </summary>
    ''' <param name="StepCheckPoint"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteStepCheckinfo(ByVal StepCheckPoint As String) As Boolean Implements uLMSStepCheckPointIBusiness.DeleteStepCheckinfo
        DeleteStepCheckinfo = False
        Dim strSQL As String = String.Format("delete from STEPCHECKPOINT sc WHERE sc.STEPCHECKPOINTid='{0}' ", StepCheckPoint)
        DatabaseHelper.ExecuteSql(strSQL)
        DeleteStepCheckinfo = True
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="productid"></param>
    ''' <param name="name"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteStepCheckinfo(ByVal productid As String, ByVal stepid As String, ByVal name As String) As Boolean Implements uLMSStepCheckPointIBusiness.DeleteStepCheckinfo
        DeleteStepCheckinfo = False
        Dim strSQL As String = String.Format("delete from STEPCHECKPOINT sc WHERE sc.PRODUCTID='{0}' AND sc.WORKFLOWSTEPID='{1}' AND sc.NAME='{2}' ", productid, stepid, name)
        DatabaseHelper.ExecuteSql(strSQL)
        DeleteStepCheckinfo = True
    End Function

    ''' <summary>
    '''删除检测项 add:Wangjh 20211112 
    ''' </summary>
    ''' <param name="StepCheckPointID"></param>
    ''' <param name="imgPath"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteStepCheckinfo(ByVal StepCheckPointID As String, ByVal imgPath As String) As Boolean Implements uLMSStepCheckPointIBusiness.DeleteStepCheckinfo
        DeleteStepCheckinfo = False
        '先清理img
        Dim dt = DatabaseHelper.Query_ReturnDatTable(String.Format("select * from STEPCHECKPOINT where STEPCHECKPOINTID='{0}'", StepCheckPointID))
        If dt.Rows.Count > 0 Then
            '删除无效img
            Dim dis As String = dt.Rows(0)("checkpointnotedis").ToString
            If Not String.IsNullOrWhiteSpace(dis) Then
                Dim list = GetImgPath(dis.ToString)
                Try
                    For Each Path As String In list
                        File.Delete(imgPath + Path)
                    Next
                Catch ex As Exception

                End Try
            End If
            dis = ""
            dis = dt.Rows(0)("drawingrequiredis").ToString
            If Not String.IsNullOrWhiteSpace(dis) Then
                Dim list = GetImgPath(dis.ToString)
                Try
                    For Each Path As String In list
                        File.Delete(imgPath + Path)
                    Next
                Catch ex As Exception

                End Try
            End If

        End If
        Dim strSQL As String = String.Format("delete from STEPCHECKPOINT sc WHERE sc.STEPCHECKPOINTid='{0}' ", StepCheckPointID)
        DatabaseHelper.ExecuteSql(strSQL)
        DeleteStepCheckinfo = True
    End Function

    ''' <summary>
    ''' add by yuxj,添加工序检测项
    ''' add by yuxj 20171228 增加图纸要求，增加工步
    ''' </summary>
    Public Function InsertIntoStepCheckPointTable(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSStepCheckPointIBusiness.InsertIntoStepCheckPointTable

        Dim strsql As String =
                        <string>
                         INSERT INTO STEPCHECKPOINT
                        (tempdealfail,CHECKINPUTTYPE,CHECKNO,CHECKPOINTNOTE,CHECKTYPE,INPUTNUM,KEYCHECK,MEOPCHECK,NAME, PRODUCTID,
                          QUALITYCHECK,STEPCHECKPOINTID, WORKFLOWSTEPID,intime,DrawingRequire, stepinfoid
                        </string>.Value
        If para.ContainsKey("checkpointnotedis") Then 'add:Wangjh 202111103
            strsql += ",checkpointnotedis "
        End If
        If para.ContainsKey("drawingrequiredis") Then 'add:Wangjh 202111103
            strsql += ",drawingrequiredis "
        End If

        If para.ContainsKey("IsInstall") Then 'add:longb 2023-03-14
            strsql += ",IsInstall,IsDisassemble,IsNotice,IsReturn,IsCompp"
        End If

        strsql += " ) VALUES( "
        strsql += String.Format("0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',{12},'{13}','{14}'",
                             para("checkinputtype"), para("checkno"), para("checkpointnote"), para("checktype"), para("inputnum"),
                             para("keycheck"), para("meopcheck"), para("name"), para("productid"), para("qualitycheck"),
                             Guid.NewGuid.ToString, para("workflowstepid"), "sysdate", para("drawingrequire").Replace("'", "''"), para("stepinfoid"))
        If para.ContainsKey("checkpointnotedis") Then 'add:Wangjh 202111103
            strsql += String.Format(",'{0}' ", para("checkpointnotedis"))
        End If
        If para.ContainsKey("drawingrequiredis") Then 'add:Wangjh 202111103
            strsql += String.Format(",'{0}' ", para("drawingrequiredis"))
        End If

        If para.ContainsKey("IsInstall") Then 'add:longb 2023-03-14 安装单、拆卸单、通知单、返回单、综合性能表
            strsql += String.Format(",'{0}','{1}','{2}','{3}','{4}' ", para("IsInstall"), para("IsDisassemble"), para("IsNotice"), para("IsReturn"), para("IsCompp"))
        End If

        strsql += ")"
        If (DatabaseHelper.ExecuteSql(strsql) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 更新工序检测项
    ''' </summary>
    Public Function UpdateStepCheckPoint(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSStepCheckPointIBusiness.UpdateStepCheckPoint

        'Dim strsql As String = String.Format("UPDATE STEPCHECKPOINT SET  CHECKPOINTNOTE='{0}',INPUTNUM='{1}',KEYCHECK='{2}',MEOPCHECK='{3}',NAME='{4}',QUALITYCHECK='{5}',DrawingRequire='{6}'" +
        '                                     " WHERE STEPCHECKPOINTID='{7}'",
        '                    para("checkpointnote"), para("inputnum"), para("keycheck"), para("meopcheck"), para("name"), para("qualitycheck"), para("drawingrequire"),
        '                    para("stepcheckpointid"))

        Dim strsql As String = String.Format("UPDATE STEPCHECKPOINT SET tempdealfail=0,INPUTNUM='{0}',KEYCHECK='{1}',MEOPCHECK='{2}',NAME='{3}',QUALITYCHECK='{4}'" +
                                             " WHERE STEPCHECKPOINTID='{5}'",
                            para("inputnum"), para("keycheck"), para("meopcheck"), para("name"), para("qualitycheck"), para("stepcheckpointid"))
        If (DatabaseHelper.ExecuteSql(strsql) > 0) Then
            'add by yuxj 20171229
            If para.ContainsKey("checkpointnote") Then
                If para("checkpointnote") <> String.Empty Then
                    strsql = String.Format("UPDATE STEPCHECKPOINT SET  CHECKPOINTNOTE='{0}'  WHERE STEPCHECKPOINTID='{1}'", para("checkpointnote"), para("stepcheckpointid"))
                    DatabaseHelper.ExecuteSql(strsql)
                End If
            End If

            If para.ContainsKey("drawingrequire") Then
                If para("drawingrequire") <> String.Empty Then
                    strsql = String.Format("UPDATE STEPCHECKPOINT SET DrawingRequire='{0}' WHERE STEPCHECKPOINTID='{1}'", para("drawingrequire"), para("stepcheckpointid"))
                    DatabaseHelper.ExecuteSql(strsql)
                End If
            End If
            'add by longb 2023-03-14 安装单、拆卸单、通知单、返回单、综合性能表
            If para.ContainsKey("IsInstall") Then
                If para("IsInstall") <> String.Empty Then
                    strsql = String.Format("UPDATE STEPCHECKPOINT SET IsInstall='{0}',IsDisassemble='{1}',IsNotice='{2}',IsReturn='{3}',IsCompp='{4}' WHERE STEPCHECKPOINTID='{5}'", para("IsInstall"), para("IsDisassemble"), para("IsNotice"), para("IsReturn"), para("IsCompp"), para("stepcheckpointid"))
                    DatabaseHelper.ExecuteSql(strsql)
                End If
            End If
            '更新时先删除无效的img
            Dim dt = DatabaseHelper.Query_ReturnDatTable(String.Format("select * from STEPCHECKPOINT where STEPCHECKPOINTID='{0}'", para("stepcheckpointid")))
            If para.ContainsKey("checkpointnotedis") Then
                '删除无效img
                Dim dis As String = dt.Rows(0)("checkpointnotedis").ToString
                If Not String.IsNullOrWhiteSpace(dis) Then
                    Dim list = GetImgPath(dis.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(para("UsingImgPath") + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If

                strsql = String.Format("UPDATE STEPCHECKPOINT SET checkpointnotedis='{0}' WHERE STEPCHECKPOINTID='{1}'", para("checkpointnotedis"), para("stepcheckpointid"))
                DatabaseHelper.ExecuteSql(strsql)
            End If

            If para.ContainsKey("drawingrequiredis") Then
                '删除无效img
                Dim dis As String = dt.Rows(0)("drawingrequiredis").ToString
                If Not String.IsNullOrWhiteSpace(dis) Then
                    Dim list = GetImgPath(dis.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(para("UsingImgPath") + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If

                strsql = String.Format("UPDATE STEPCHECKPOINT SET drawingrequiredis='{0}' WHERE STEPCHECKPOINTID='{1}'", para("drawingrequiredis"), para("stepcheckpointid"))
                DatabaseHelper.ExecuteSql(strsql)
            End If

            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 获取批次工序实测值数据
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks>Modify YangJiang 20180731 SCPR.NOTES</remarks>
    Public Function GetStepCheckPointResultData(ByVal para As Dictionary(Of String, String)) As DataTable Implements IBusiness.uLMSStepCheckPointIBusiness.GetStepCheckPointResultData
        GetStepCheckPointResultData = New DataTable
        Dim sb As New StringBuilder
        sb.AppendLine("SELECT SCPR.CONTAINERID,SCPR.FACTORYID,SCPR.STEPCHECKPOINTID,SCPR.STEPCHECKPOINTRESULTID,")
        sb.AppendLine(" E.FULLNAME CHECKER,SCPR.CHECKERID,SCPR.CHECKPOINTRESULTNOTE,SCPR.CHECKDATE,SCPR.NOTES,")
        sb.AppendLine(" E1.FULLNAME WORKER,SCPR.WORKERID,SCPR.WORKCHECKPOINTRESULTNOTE,SCPR.CREATEDATE,SCPR.INPUTSEQ，c.containername ")
        sb.AppendLine("  FROM STEPCHECKPOINTRESULT SCPR")
        sb.AppendLine("  LEFT JOIN container c ON scpr.containerid = c.containerid")
        sb.AppendLine("  LEFT JOIN EMPLOYEE E ON E.EMPLOYEEID = SCPR.CHECKERID")
        sb.AppendLine("  LEFT JOIN EMPLOYEE E1 ON E1.EMPLOYEEID = SCPR.WORKERID")
        sb.AppendLine("  LEFT JOIN STEPCHECKPOINT SCP ON SCP.STEPCHECKPOINTID=SCPR.STEPCHECKPOINTID")
        sb.AppendFormat(" WHERE SCP.WORKFLOWSTEPID = '{0}' ", para("StepID"))
        If para.ContainsKey("ContainerID") Then
            sb.AppendFormat(" AND SCPR.CONTAINERID='{0}' ", para("ContainerID"))
        End If
        If para.ContainsKey("ContainerIDs") Then
            sb.AppendFormat(" AND SCPR.CONTAINERID IN ({0}) ", para("ContainerIDs"))
        End If
        If para.ContainsKey("StepCheckPointID") Then
            sb.AppendFormat(" AND SCP.STEPCHECKPOINTID IN ('{0}') ", para("StepCheckPointID").Replace(",", "','")) 'modify by lb 20250217
        End If
        sb.AppendLine("  ORDER BY SCPR.CONTAINERID,SCPR.INPUTSEQ")
        GetStepCheckPointResultData = DatabaseHelper.Query_ReturnDatTable(sb.ToString)
    End Function

    ''' <summary>
    ''' 添加实测值信息
    ''' Modify by Yuxj 20180124 添加录入次数inputseq 
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AddStepCheckResultInfo(ByVal para As Dictionary(Of String, String)) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.AddStepCheckResultInfo
        AddStepCheckResultInfo = False
        Dim strsql As String = ""
        Dim count As Integer
        If para("isWorker") = 1 Then
            strsql =
            <string>
                INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,WORKERID,WORKCHECKPOINTRESULTNOTE,WORKCHECKPOINTRESULTNOTEDIS,CONTAINERID,CREATEDATE,FACTORYID,STEPCHECKPOINTID,STEPCHECKPOINTRESULTID,inputseq)
                VALUES (sysdate,0,:CHECKERID,:CHECKPOINTRESULTNOTE,:WORKCHECKPOINTRESULTNOTEDIS,:CONTAINERID,SYSDATE,:FACTORYID, :STEPCHECKPOINTID,:STEPCHECKPOINTRESULTID,:inputseq)
            </string>
            count = 7
        Else
            strsql =
                <string>
                INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,CHECKERID, CHECKPOINTRESULTNOTE,CHECKPOINTRESULTNOTEDIS,CONTAINERID,CHECKDATE,FACTORYID,STEPCHECKPOINTID,STEPCHECKPOINTRESULTID,inputseq,NOTES)
                VALUES (sysdate,0,:CHECKERID,:CHECKPOINTRESULTNOTE,:WORKCHECKPOINTRESULTNOTEDIS,:CONTAINERID,SYSDATE,:FACTORYID, :STEPCHECKPOINTID,:STEPCHECKPOINTRESULTID,:inputseq,:NOTES)
            </string>
            count = 8
        End If

        Dim insertpara(count) As OracleParameter
        insertpara(0) = DatabaseHelper.NewParameter(":CHECKERID", para("CheckerID"), OracleType.VarChar)
        insertpara(1) = DatabaseHelper.NewParameter(":CHECKPOINTRESULTNOTE", para("CheckPointResultNote"), OracleType.VarChar)
        insertpara(2) = DatabaseHelper.NewParameter(":WORKCHECKPOINTRESULTNOTEDIS", para("WORKCHECKPOINTRESULTNOTEDIS"), OracleType.VarChar) 'add by longb 2022-12-18
        insertpara(3) = DatabaseHelper.NewParameter(":CONTAINERID", para("ContainerID"), OracleType.VarChar)
        insertpara(4) = DatabaseHelper.NewParameter(":FACTORYID", para("FactoryID"), OracleType.VarChar)
        insertpara(5) = DatabaseHelper.NewParameter(":STEPCHECKPOINTID", para("StepCheckPointID"), OracleType.VarChar)
        insertpara(6) = DatabaseHelper.NewParameter(":STEPCHECKPOINTRESULTID", para("StepCheckPointResultID"), OracleType.VarChar)

        'Modify by Yuxj 20180124 添加录入次数inputseq 
        insertpara(7) = DatabaseHelper.NewParameter(":inputseq", (GetMaxSequenceById(para("StepCheckPointID"), para("ContainerID"), para("FactoryID")) + 1).ToString, OracleType.VarChar)
        'add YangJiang 20180731 增加备注
        If para("isWorker") <> 1 Then
            'Modify by Yuxj20180816 增加对字典中是否有Notes关键字的判断
            If para.ContainsKey("Notes") Then
                insertpara(8) = DatabaseHelper.NewParameter(":NOTES", para("Notes"), OracleType.VarChar)
            Else
                insertpara(8) = DatabaseHelper.NewParameter(":NOTES", String.Empty, OracleType.VarChar)
            End If

        End If

        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql, insertpara)
        If row > 0 Then
            AddStepCheckResultInfo = True
        End If
    End Function

    ''' <summary>
    ''' 更新实测值信息
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateStepCheckResultInfo(ByVal para As Dictionary(Of String, String)) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.UpdateStepCheckResultInfo
        UpdateStepCheckResultInfo = False
        Dim strsql As String = ""
        Dim count As Integer
        If para("isWorker") = 1 Then
            strsql =
                <string>
                    UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,WORKERID=:CHECKERID,WORKCHECKPOINTRESULTNOTE=:CHECKPOINTRESULTNOTE,WORKCHECKPOINTRESULTNOTEDIS=:WORKCHECKPOINTRESULTNOTEDIS,CHECKDATE=SYSDATE WHERE STEPCHECKPOINTRESULTID=:STEPCHECKPOINTRESULTID
                </string>
            count = 3
        Else
            strsql =
                <string>
                    UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,CHECKERID=:CHECKERID,CHECKPOINTRESULTNOTE=:CHECKPOINTRESULTNOTE,CHECKPOINTRESULTNOTEDIS=:WORKCHECKPOINTRESULTNOTEDIS,NOTES=:NOTES,CHECKDATE=SYSDATE WHERE STEPCHECKPOINTRESULTID=:STEPCHECKPOINTRESULTID
                </string>
            count = 4
        End If

        Dim insertpara(count) As OracleParameter
        insertpara(0) = DatabaseHelper.NewParameter(":CHECKERID", para("CheckerID"), OracleType.VarChar)
        insertpara(1) = DatabaseHelper.NewParameter(":CHECKPOINTRESULTNOTE", para("CheckPointResultNote"), OracleType.VarChar)
        insertpara(2) = DatabaseHelper.NewParameter(":WORKCHECKPOINTRESULTNOTEDIS", para("WORKCHECKPOINTRESULTNOTEDIS"), OracleType.VarChar) 'add by longb 2022-12-18

        insertpara(3) = DatabaseHelper.NewParameter(":STEPCHECKPOINTRESULTID", para("StepCheckPointResultID"), OracleType.VarChar)
        'add YangJiang 20180731 增加备注
        If para("isWorker") <> 1 Then
            'insertpara(3) = DatabaseHelper.NewParameter(":Notes", para("NOTES"), OracleType.VarChar) 'Modify by Yuxj20180816 NOTES-> Notes

            'Modify by Yuxj20180816 增加对字典中是否有Notes关键字的判断 NOTES ->Notes
            If para.ContainsKey("Notes") Then
                insertpara(4) = DatabaseHelper.NewParameter(":NOTES", para("Notes"), OracleType.VarChar)
            Else
                insertpara(4) = DatabaseHelper.NewParameter(":NOTES", String.Empty, OracleType.VarChar)
            End If
        End If
        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql, insertpara)
        If row > 0 Then
            UpdateStepCheckResultInfo = True
        End If
    End Function

    ''' <summary>
    ''' Add by Yuxj20180124  获取当前(非装试)工序/(装试)工步实测值的最大录入次数
    ''' </summary>
    ''' <param name="StepCheckPointId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetMaxSequenceById(ByVal StepCheckPointId As String, ByVal containerid As String, ByVal factoryid As String) As Integer Implements uLMSStepCheckPointIBusiness.GetMaxSequenceById
        Dim strsql As String = String.Format(" select count(1) maxSequence from STEPCHECKPOINTRESULT where stepcheckpointid='{0}' and containerid='{1}' and factoryid='{2}' ", StepCheckPointId, containerid, factoryid)
        Return Convert.ToInt32(DatabaseHelper.Query_ReturnDatTable(strsql).Rows(0)("maxSequence").ToString)
    End Function

    ''' <summary>
    ''' 保存实测值信息（检验员） Add by Duht20201201 edit by zhangrj 2021-11-11
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveCheckResultByCheck(ByVal para As Dictionary(Of String, String)) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.SaveCheckResultByCheck
        SaveCheckResultByCheck = False
        Dim strsql As New StringBuilder
        If para("StepCheckPointResultID") = Nothing Then
            strsql.Clear()
            strsql.AppendLine("INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,CHECKERID,CHECKPOINTRESULTNOTE,CHECKPOINTRESULTNOTEDIS,CONTAINERID,CHECKDATE,FACTORYID,")
            strsql.AppendLine("STEPCHECKPOINTID,STEPCHECKPOINTRESULTID,containerstepworkreportid,NOTES,CHILDCONTAINERID) VALUES(sysdate,0,")
            strsql.AppendFormat("'{0}',", para("CheckerID"))
            strsql.AppendFormat("'{0}',", para("CheckPointResultNote"))
            strsql.AppendFormat("'{0}',", para("CheckPointResultNoteDis"))
            strsql.AppendFormat("'{0}',", para("ContainerID"))
            strsql.AppendFormat("{0},", "sysdate")
            strsql.AppendFormat("'{0}',", para("FactoryID"))
            strsql.AppendFormat("'{0}',", para("StepCheckPointID"))
            strsql.AppendFormat("'{0}',", Guid.NewGuid.ToString)
            strsql.AppendFormat("'{0}',", para("ContainerStepWorkReportID"))
            strsql.AppendFormat("'{0}','{1}')", "", para("ChildContainerID"))
        Else
            If para.ContainsKey("UsingImgPath") Then '先清除文件夹中的记录
                Dim dis = DatabaseHelper.GetSingle(String.Format("select checkpointresultnotedis from STEPCHECKPOINTRESULT where STEPCHECKPOINTRESULTid='{0}'", para("StepCheckPointResultID")))
                If dis IsNot Nothing Then
                    Dim list = GetImgPath(dis.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(para("UsingImgPath") + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
            strsql.AppendLine("UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,")
            strsql.AppendFormat("CHECKDATE=sysdate,CHECKPOINTRESULTNOTE='{0}', ", para("CheckPointResultNote"))
            strsql.AppendFormat("CHECKPOINTRESULTNOTEDIS='{0}', ", para("CheckPointResultNoteDis"))
            If para.ContainsKey("CheckResultDocPath") Then
                strsql.AppendFormat("checkresultdocpath='{0}', ", para("CheckResultDocPath"))
            End If
            strsql.AppendFormat("CheckerID='{0}' ", para("CheckerID"))
            'strsql.AppendFormat("ContainerStepWorkReportID='{0}' ", para("ContainerStepWorkReportID"))
            strsql.AppendFormat(" where STEPCHECKPOINTRESULTID='{0}'", para("StepCheckPointResultID"))
        End If
        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql.ToString())
        If row > 0 Then
            SaveCheckResultByCheck = True
        End If
    End Function

    ''' <summary>
    ''' 保存实测值检验信息，批量带子序号
    ''' add:Wangjh 20211115
    ''' </summary>
    ''' <param name="para"></param>
    ''' <param name="childDt"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveCheckResultByCheck(ByVal para As Dictionary(Of String, String), ByVal childDt As DataTable) Implements IBusiness.uLMSStepCheckPointIBusiness.SaveCheckResultByCheck
        If childDt Is Nothing Then
            Return False
        End If
        If childDt.Rows.Count = 0 Then
            Return False
        End If
        Dim strSqlList As New ArrayList
        Dim insertSql = <string> INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,CHECKERID,CHECKPOINTRESULTNOTE,CHECKPOINTRESULTNOTEDIS,CONTAINERID,CHECKDATE,FACTORYID,STEPCHECKPOINTID,STEPCHECKPOINTRESULTID,containerstepworkreportid,NOTES,CHILDCONTAINERID) 
                                VALUES(sysdate,0,'{0}','{1}','{2}','{3}',sysdate,'{4}','{5}',sys_guid(),'{6}','{7}','{8}')</string>.Value
        Dim updateSql = <string>UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,CHECKPOINTRESULTNOTE='{0}',CHECKPOINTRESULTNOTEDIS='{1}',CheckerID='{2}',checkdate=sysdate,ContainerStepWorkReportID='{3}',checkresultdocpath='{4}' where STEPCHECKPOINTRESULTID='{5}'</string>.Value
        Dim selectSql = " select * from stepcheckpointresult sc where sc.stepcheckpointid='{0}' and sc.containerid='{1}' and sc.childcontainerid='{2}' "
        For Each row As DataRow In childDt.Rows
            Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(selectSql, para("StepCheckPointID"), row("containerid"), row("childcontainerid")))
            If dt.Rows.Count > 0 Then
                For Each childCheck As DataRow In dt.Rows
                    If para.ContainsKey("UsingImgPath") Then '先清除文件夹中的记录
                        DeleteCheckResultById(childCheck("stepcheckpointresultid").ToString, para("UsingImgPath"))
                    End If
                    If String.IsNullOrWhiteSpace(childCheck("workcheckpointresultnotedis").ToString) And String.IsNullOrWhiteSpace(childCheck("secondcheckpointnotedis").ToString) Then '插入
                        strSqlList.Add(String.Format(insertSql, para("CheckerID"), para("CheckPointResultNote"), para("CheckPointResultNoteDis"), row("containerid"), para("FactoryID"), para("StepCheckPointID"), para("ContainerStepWorkReportID"), "", row("childcontainerid").ToString))
                    Else '更新
                        Dim checkresultdocpath = childCheck("checkresultdocpath").ToString()
                        If String.IsNullOrWhiteSpace(checkresultdocpath) Then
                            checkresultdocpath = childCheck("workresultdocpath").ToString()
                        End If
                        strSqlList.Add(String.Format(updateSql, para("CheckPointResultNote"), para("CheckPointResultNoteDis"), para("CheckerID"), para("ContainerStepWorkReportID"), checkresultdocpath, childCheck("StepCheckPointResultID").ToString))
                    End If
                Next
            Else
                strSqlList.Add(String.Format(insertSql, para("CheckerID"), para("CheckPointResultNote"), para("CheckPointResultNoteDis"), row("containerid"), para("FactoryID"), para("StepCheckPointID"), para("ContainerStepWorkReportID"), "", row("childcontainerid").ToString))
            End If

        Next

        DatabaseHelper.ExecuteSqlTran(strSqlList)
        Return True
    End Function

    ''' <summary>
    ''' 保存实测值信息（二检） Add by zhangrj 20220824 
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveCheckResultBySecondCheck(ByVal para As Dictionary(Of String, String)) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.SaveCheckResultBySecondCheck
        SaveCheckResultBySecondCheck = False
        Dim strsql As New StringBuilder
        If para("StepCheckPointResultID") = Nothing Then
            strsql.Clear()
            strsql.AppendLine("INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,SECONDCHECKID,SECONDCHECKPOINTNOTEDIS,SECONDDATE,CONTAINERID,CHECKDATE,FACTORYID,")
            strsql.AppendLine("STEPCHECKPOINTID,STEPCHECKPOINTRESULTID,containerstepworkreportid,NOTES,CHILDCONTAINERID) VALUES(sysdate,0,")
            strsql.AppendFormat("'{0}',", para("SecondCheckID"))
            strsql.AppendFormat("'{0}',", para("SecondCheckPointNoteDis"))
            strsql.AppendFormat("{0},", "sysdate")
            strsql.AppendFormat("'{0}',", para("ContainerID"))
            strsql.AppendFormat("{0},", "sysdate")
            strsql.AppendFormat("'{0}',", para("FactoryID"))
            strsql.AppendFormat("'{0}',", para("StepCheckPointID"))
            strsql.AppendFormat("'{0}',", Guid.NewGuid.ToString)
            strsql.AppendFormat("'{0}',", para("ContainerStepWorkReportID"))
            strsql.AppendFormat("'{0}','{1}')", "", para("ChildContainerID"))
        Else
            If para.ContainsKey("UsingImgPath") Then '先清除文件夹中的记录
                Dim dis = DatabaseHelper.GetSingle(String.Format("select secondcheckpointnotedis from STEPCHECKPOINTRESULT where STEPCHECKPOINTRESULTid='{0}'", para("StepCheckPointResultID")))
                If dis IsNot Nothing Then
                    Dim list = GetImgPath(dis.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(para("UsingImgPath") + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
            strsql.AppendLine("UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,SECONDDATE=sysdate,tempdealfail=0,")
            strsql.AppendFormat("SECONDCHECKPOINTNOTEDIS='{0}', ", para("SecondCheckPointNoteDis"))
            strsql.AppendFormat("SECONDCHECKID='{0}' ", para("SecondCheckID"))
            'strsql.AppendFormat("ContainerStepWorkReportID='{0}' ", para("ContainerStepWorkReportID"))
            strsql.AppendFormat(" where STEPCHECKPOINTRESULTID='{0}'", para("StepCheckPointResultID"))
        End If
        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql.ToString())
        If row > 0 Then
            SaveCheckResultBySecondCheck = True
        End If
    End Function

    ''' <summary>
    ''' 保存实测值信息（工人） Add by Duht20201201
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveCheckResultByWorker(ByVal para As Dictionary(Of String, String)) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.SaveCheckResultByWorker
        SaveCheckResultByWorker = False
        Dim stepCheckPointResultID As String = Guid.NewGuid.ToString 'add by longb 2022-12-09 
        Dim strsql As New StringBuilder
        Dim insertSendGKWDatasql As New StringBuilder '插入待发送给工控网的数据sql add by longb 2022-12-09
        If Not para.ContainsKey("StepCheckPointResultID") Then
            If Not para.ContainsKey("IsBatch") Then
                'add:Wangjh 同一个检测项，同一批次，同一个子序号，同一个结果。暂时只能录一次，防止产生大量重复结果 2022/10/12
                strsql.AppendFormat("select 1 from STEPCHECKPOINTRESULT where StepCheckPointID='{0}' and ContainerID='{1}'", para("StepCheckPointID"), para("ContainerID"))
                If para.ContainsKey("ChildContainerID") Then
                    If Not String.IsNullOrWhiteSpace(para("ChildContainerID")) Then
                        strsql.AppendFormat(" and ChildContainerID='{0}'", para("ChildContainerID"))
                    End If
                End If
                If DatabaseHelper.GetSingle(strsql.ToString) IsNot Nothing Then
                    Return True
                    Exit Function
                End If
            End If
            strsql.Clear()
            strsql.AppendLine("INSERT INTO STEPCHECKPOINTRESULT (lastchangedate,tempdealfail,WORKERID,WORKCHECKPOINTRESULTNOTE,WORKCHECKPOINTRESULTNOTEDIS,CONTAINERID,ChildContainerID,CREATEDATE,FACTORYID,STEPCHECKPOINTID,")
            strsql.AppendLine("STEPCHECKPOINTRESULTID) VALUES (sysdate,0,")
            strsql.AppendFormat("'{0}',", para("WORKERID"))
            strsql.AppendFormat("'{0}',", para("WORKCHECKPOINTRESULTNOTE"))
            strsql.AppendFormat("'{0}',", para("WORKCHECKPOINTRESULTNOTEDIS"))
            strsql.AppendFormat("'{0}',", para("ContainerID"))
            strsql.AppendFormat("'{0}',", para("ChildContainerID"))
            strsql.AppendFormat("{0},", "sysdate")
            strsql.AppendFormat("'{0}',", para("FactoryID"))
            strsql.AppendFormat("'{0}',", para("StepCheckPointID"))
            strsql.AppendFormat("'{0}')", stepCheckPointResultID) 'modify by longb 2022-12-09
            insertSendGKWDatasql.AppendFormat("insert into Sendgkwdata(ID,Parentid,Sendtype)values('{0}','{1}','{2}')", Guid.NewGuid.ToString, stepCheckPointResultID, "2") 'add by longb 2022-12-09
        Else
            If para.ContainsKey("UsingImgPath") Then '先清除文件夹中的记录
                Dim dis = DatabaseHelper.GetSingle(String.Format("select WORKCHECKPOINTRESULTNOTEDIS from STEPCHECKPOINTRESULT where STEPCHECKPOINTRESULTid='{0}'", para("StepCheckPointResultID")))
                If dis IsNot Nothing Then
                    Dim list = GetImgPath(dis.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(para("UsingImgPath") + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
            stepCheckPointResultID = para("StepCheckPointResultID")
            strsql.AppendLine("UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,")
            strsql.AppendFormat("WORKCHECKPOINTRESULTNOTE='{0}', WORKCHECKPOINTRESULTNOTEDIS='{1}',", para("WORKCHECKPOINTRESULTNOTE"), para("WORKCHECKPOINTRESULTNOTEDIS"))
            strsql.AppendFormat("WORKERID='{0}' ", para("WORKERID"))
            strsql.AppendFormat("where STEPCHECKPOINTRESULTID='{0}'", para("StepCheckPointResultID"))
            DatabaseHelper.ExecuteSql(String.Format("update Sendgkwdata set issend=0 where Parentid='{0}'", para("StepCheckPointResultID"))) 'add by longb 2022-12-22 检测项修改，更新issend重新发送
        End If
        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql.ToString())
        If row > 0 Then
            If Not String.IsNullOrWhiteSpace(insertSendGKWDatasql.ToString) And para.ContainsKey("SendToSZB") Then '新增录入，写入Sendgkwdata发送给三坐标 add by longb 2022-12-09
                DatabaseHelper.ExecuteSql(insertSendGKWDatasql.ToString)
            End If
            SaveCheckResultByWorker = True
        End If
        SaveStepCheckPointSPCMonitor(stepCheckPointResultID)
    End Function

#Region "工人录入"

    ''' <summary>
    ''' 获取工人录入及未录入的检测项信息
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetStepCheckInfoByWorker(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSStepCheckPointIBusiness.GetStepCheckInfoByWorker
        Dim strSql = <string>select sonc.containername ChildContainerName,st.name,st.checkpointnotedis_b,st.CheckPointNoteDis,st.checkpointnote,st.drawingrequiredis_b,st.DrawingRequireDis,st.drawingrequire,decode(st.CheckType,3,'设计特性',4,'过程参数') CheckTypename,st.CheckType,st.KeyCheck,decode(st.keycheck,0,'否',1,'是')  keycheckname,st.qualitycheck,
decode(st.qualitycheck,0,'否',1,'是') qualitycheckname,decode(st.tccheckpointnote,null,'否','是') istcm,st.stepinfoid,st.productid,st.workflowstepid,sc.workcheckpointresultnote,sc.workcheckpointresultnotedis,
e.fullname workername,sc.createdate InputCreateDate,st.stepcheckpointid,sc.stepcheckpointresultid,sc.workresultdocpath from stepcheckpoint ST
left join stepcheckpointresult sc on sc.stepcheckpointid=st.stepcheckpointid and sc.containerid='{0}' and sc.containerstepworkreportid is null </string>.Value
        strSql = String.Format(strSql, para("ContainerID"))
        If para.ContainsKey("WorkerID") Then '工人
            If Not String.IsNullOrWhiteSpace(para("WorkerID")) Then
                strSql += String.Format(" and sc.WorkerID='{0}' ", para("WorkerID"))
                strSql = String.Format(strSql, para("WorkerID"))
            End If
        End If
        strSql += <string> left join container sonc on sonc.containerid=sc.childcontainerid
left join employee e on e.employeeid=sc.workerid
 where  st.workflowstepid='{0}' </string>.Value

        strSql = String.Format(strSql, para("WorkflowStepID"))

        If para.ContainsKey("ProductID") Then
            If Not String.IsNullOrWhiteSpace(para("ProductID")) Then
                strSql += String.Format(" and st.productid='{0}' ", para("ProductID"))
            End If
        End If
        '新增工步检测项 add by zhangrj 2022-08-04
        If para.ContainsKey("StepInfoId") Then
            If Not String.IsNullOrWhiteSpace(para("StepInfoId")) Then
                strSql += String.Format(" and st.StepInfoId='{0}' ", para("StepInfoId"))
            End If
        End If
        strSql += " order by st.intime desc "

        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 根据展示的html，获取其中所有的特殊字符图片路径
    ''' add:Wangjh 20211112
    ''' </summary>
    ''' <param name="dis"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetImgPath(ByVal dis As String) As List(Of String)
        Dim imgPathList As New List(Of String)

        'Dim o = dis.Split("<img")
        'For Each r In o
        '    Dim index = r.IndexOf("ImageTemp")
        '    If index = -1 Then
        '        Continue For
        '    End If
        '    Dim imgPath = r.Substring(index)
        '    If Not String.IsNullOrWhiteSpace(imgPath) Then
        '        index = imgPath.IndexOf(""">")
        '        If index = -1 Then
        '            Continue For
        '        End If
        '        imgPath = imgPath.Substring(0, index)
        '        If Not String.IsNullOrWhiteSpace(imgPath) Then
        '            imgPathList.Add(imgPath)
        '        End If
        '    End If
        'Next

        Dim strReg = "ImageTemp(.)+?\.png"

        Dim matchs = Regex.Matches(dis, strReg)

        For Each m As Match In matchs
            imgPathList.Add(m.Value)
        Next

        Return imgPathList
    End Function
#End Region

    ''' <summary>
    ''' 获取报工信息，检测项录入使用
    ''' add:wangjh 20211103
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetWorkreportInfoByContainer(ByVal para As Dictionary(Of String, String)) As DataTable Implements IBusiness.uLMSStepCheckPointIBusiness.GetWorkreportInfoByContainer
        Dim strSql = <string>select c.containername,c.containerid,em.employeeid,em.employeename,em.fullname,csw.createdate,csw.qty,NVL(CSW.LOSSQTY,0) LOSSQTY,c.qty qtys,'' stepinfoid,'' stepinfoname,
NVL(CSW.SELFCHECKQUALIFIEDQTY,0) SELFCHECKQUALIFIEDQTY,NVL(CSW.SELFCHECKOUTOFTOLERANCEQTY,0) SELFCHECKOUTOFTOLERANCEQTY,NVL(CSW.SELFCHECKLOSSQTY,0) SELFCHECKLOSSQTY
,NVL(CSW.QTY2,0) QTY2,NVL(SpecimenQty,0) SpecimenQty,NVL(SpecimenLossQty,0) SpecimenLossQty,CSW.checktype,ws.workflowstepname,ws.workflowstepid,c.productdescription,c.containertype,csw.containerstepworkreportid from  containerstepworkreport csw
left join containercurrentinfo c on c.containerid=csw.containerid
left join workflowstep ws on ws.workflowstepid=csw.workflowstepid
LEFT JOIN EMPLOYEE EM ON EM.EMPLOYEEID = CSW.WORKERID
where csw.containerid in ('{0}') and csw.workflowstepid='{1}' 
and csw.isuse=0</string>.Value
        strSql = String.Format(strSql, para("ContainerID"), para("WorkflowStepID"))
        If para.Keys.Contains("StepInfoID") Then '增加工步查询 add by zhangrj 20220809
            strSql = <string>select c.containername,c.containerid,em.employeeid,em.employeename,em.fullname,csw.createdate,csw.qty,NVL(CSW.LOSSQTY,0) LOSSQTY,c.qty qtys,
NVL(CSW.SELFCHECKQUALIFIEDQTY,0) SELFCHECKQUALIFIEDQTY,NVL(CSW.SELFCHECKOUTOFTOLERANCEQTY,0) SELFCHECKOUTOFTOLERANCEQTY,NVL(CSW.SELFCHECKLOSSQTY,0) SELFCHECKLOSSQTY
,NVL(CSW.QTY2,0) QTY2,NVL(SpecimenQty,0) SpecimenQty,NVL(SpecimenLossQty,0) SpecimenLossQty,CSW.checktype,ws.workflowstepname,ws.workflowstepid,c.productdescription,
c.containertype,csw.containerstepworkreportid,s.stepinfoid,s.description stepinfoname
from  containerstepworkreport2 csw
LEFT JOIN containercheckinfo2 cc ON cc.containerstepworkreportid = csw.containerstepworkreportid AND cc.isuse = 0
left join containercurrentinfo c on c.containerid=csw.containerid
left join workflowstep ws on ws.workflowstepid=csw.workflowstepid
LEFT JOIN stepinfo s ON s.stepinfoid = csw.stepinfoid
LEFT JOIN EMPLOYEE EM ON EM.EMPLOYEEID = CSW.WORKERID
where csw.containerid in ('{0}') and csw.workflowstepid='{1}' and csw.stepinfoid = '{2}'
and csw.isuse=0 AND cc.containercheckinfoid IS NULL</string>.Value
            strSql = String.Format(strSql, para("ContainerID"), para("WorkflowStepID"), para("StepInfoID"))
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 删除实测值信息（通过ID） add by zhangrj 2021-11-12
    ''' 'update wangjh 删除时增加删除img文件 20211112
    ''' </summary>
    ''' <param name="checkResultId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteCheckResultById(ByVal checkResultId As String, ByVal usingImgPath As String) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.DeleteCheckResultById
        DeleteCheckResultById = False
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format("select * from stepcheckpointresult where stepcheckpointresultid='{0}'", checkResultId))

        '先处理文件夹的img add:Wangjh 20211112
        If Not String.IsNullOrWhiteSpace(usingImgPath) Then
            If dt.Rows.Count > 0 Then
                If Not dt.Rows(0).IsNull("checkpointresultnotedis") Then
                    Dim list = GetImgPath(dt.Rows(0)("checkpointresultnotedis").ToString.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(usingImgPath + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
        End If

        '如果工人有录入信息或二检有录入信息，则只是清空检验结果字段，如果工人没有录入信息可以直接删除记录 add:Wangjh 20211115
        Dim strSql = ""
        If String.IsNullOrWhiteSpace(dt.Rows(0)("workcheckpointresultnotedis").ToString) And String.IsNullOrWhiteSpace(dt.Rows(0)("secondcheckpointnotedis").ToString) Then
            strSql = String.Format("DELETE FROM stepcheckpointresult sr WHERE sr.stepcheckpointresultid = '{0}' ", checkResultId)
        Else
            strSql = "update stepcheckpointresult set lastchangedate=sysdate,CHECKPOINTRESULTNOTE='',CHECKPOINTRESULTNOTEdis='',CheckerID='',CHECKDATE='' where stepcheckpointresultid='{0}'"
            strSql = String.Format(strSql, checkResultId)
        End If

        Dim row As Integer = DatabaseHelper.ExecuteSql(strSql.ToString())


        If row > 0 Then
            DeleteCheckResultById = True
        End If
    End Function

    ''' <summary>
    ''' 删除二检实测值信息（通过ID） add by zhangrj 2022-08-24
    ''' 'update wangjh 删除时增加删除img文件 20211112
    ''' </summary>
    ''' <param name="checkResultId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteSecondCheckResultById(ByVal checkResultId As String, ByVal usingImgPath As String) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.DeleteSecondCheckResultById
        DeleteSecondCheckResultById = False
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format("select * from stepcheckpointresult where stepcheckpointresultid='{0}'", checkResultId))

        '先处理文件夹的img add:Wangjh 20211112
        If Not String.IsNullOrWhiteSpace(usingImgPath) Then
            If dt.Rows.Count > 0 Then
                If Not dt.Rows(0).IsNull("secondcheckpointnotedis") Then
                    Dim list = GetImgPath(dt.Rows(0)("secondcheckpointnotedis").ToString.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(usingImgPath + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
        End If

        '如果工人有录入信息则只是清空检验结果字段，如果工人没有录入信息可以直接删除记录 add:Wangjh 20211115
        Dim strSql = ""
        If String.IsNullOrWhiteSpace(dt.Rows(0)("workcheckpointresultnotedis").ToString) Then
            strSql = String.Format("DELETE FROM stepcheckpointresult sr WHERE sr.stepcheckpointresultid = '{0}' ", checkResultId)
        Else
            strSql = "update stepcheckpointresult set lastchangedate=sysdate,SECONDCHECKPOINTNOTEDIS='',SECONDCHECKID='',SECONDDATE='' where stepcheckpointresultid='{0}'"
            strSql = String.Format(strSql, checkResultId)
        End If

        Dim row As Integer = DatabaseHelper.ExecuteSql(strSql.ToString())


        If row > 0 Then
            DeleteSecondCheckResultById = True
        End If
    End Function

    ''' <summary>
    ''' 删除工人实测值信息
    ''' </summary>
    ''' <param name="checkResultId"></param>
    ''' <param name="usingImgPath"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteWorkerResultById(ByVal checkResultId As String, ByVal usingImgPath As String) As Boolean Implements IBusiness.uLMSStepCheckPointIBusiness.DeleteWorkerResultById
        DeleteWorkerResultById = False
        '先处理文件夹的img add:Wangjh 20211112
        If Not String.IsNullOrWhiteSpace(usingImgPath) Then
            Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format("select * from stepcheckpointresult where stepcheckpointresultid='{0}'", checkResultId))
            If dt.Rows.Count > 0 Then
                If Not dt.Rows(0).IsNull("workcheckpointresultnotedis") Then
                    Dim list = GetImgPath(dt.Rows(0)("workcheckpointresultnotedis").ToString.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(usingImgPath + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
                If Not dt.Rows(0).IsNull("checkpointresultnotedis") Then
                    Dim list = GetImgPath(dt.Rows(0)("checkpointresultnotedis").ToString.ToString)
                    Try
                        For Each Path As String In list
                            File.Delete(usingImgPath + Path)
                        Next
                    Catch ex As Exception

                    End Try
                End If
            End If
        End If
        '
        Dim strsql As New StringBuilder
        strsql.AppendLine("DELETE FROM stepcheckpointresult sr")
        strsql.AppendFormat(" WHERE sr.stepcheckpointresultid = '{0}'", checkResultId)
        Dim row As Integer = DatabaseHelper.ExecuteSql(strsql.ToString())
        If row > 0 Then
            DeleteWorkerResultById = True
        End If
    End Function

#Region "检验录入 add by zhangrj 2021-11-11"
    ''' <summary>
    ''' 实测值录入获取检测项列表
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetInputStepCheckPointList(ByVal para As System.Collections.Generic.Dictionary(Of String, String)) As DTO.uMESProcessResult Implements IBusiness.uLMSStepCheckPointIBusiness.GetInputStepCheckPointList
        GetInputStepCheckPointList = New uMESProcessResult
        Dim HasStepinfo As Boolean = para.ContainsKey("StepinfoID")
        Dim sb As New StringBuilder
        sb.AppendLine("SELECT SC.*,DECODE(SC.CHECKINPUTTYPE, '1', '标准', '2', '临时', CHECKINPUTTYPE) CHECKINPUTTYPENAME,")
        sb.AppendLine("DECODE(SC.CHECKTYPE, '3', '设计特性', '4', '过程参数', CHECKTYPE) CHECKTYPENAME,")
        sb.AppendLine("DECODE(SC.KEYCHECK, '1', '是', '0', '否', KEYCHECK) KEYCHECKNAME,")
        sb.AppendLine("DECODE(SC.MEOPCHECK, '1', '是', '0', '否', MEOPCHECK) MEOPCHECKNAME,")
        sb.AppendLine("DECODE(SC.QUALITYCHECK, '1', '是', '0', '否', QUALITYCHECK) QUALITYCHECKNAME,")
        sb.AppendLine("DECODE(SC.TCCHECKPOINTNOTE, NULL, '否', '是') ISTCM, sr.*,c.containername ChildContainerName")
        sb.AppendLine("  FROM stepcheckpoint SC LEFT JOIN stepcheckpointresult sr ON SC.stepcheckpointid = sr.stepcheckpointid")
        If para.ContainsKey("ContainerID") Then
            sb.AppendFormat(" AND sr.containerid = '{0}' ", para("ContainerID"))
        End If
        If para.ContainsKey("ContainerStepWorkReportID") Then 'add:Wangjh 20211115
            sb.AppendFormat(" and (sr.containerstepworkreportid='{0}'  ) ", para("ContainerStepWorkReportID"))
        End If

        sb.AppendLine("  LEFT JOIN Container c ON sr.childcontainerid = c.containerid")
        sb.AppendLine(" where 1=1 ")
        If para.ContainsKey("StepID") Then
            sb.AppendFormat(" and SC.WORKFLOWSTEPID = '{0}' ", para("StepID"))
        End If
        If para.ContainsKey("ProductID") Then 'add:Wangjh 20211115
            sb.AppendFormat(" and sc.productid='{0}' ", para("ProductID"))
        End If

        If para.ContainsKey("StepInfoID") Then
            If Not String.IsNullOrWhiteSpace(para("StepInfoID").ToString) Then
                sb.AppendFormat(" and sc.stepinfoid='{0}' ", para("StepInfoID"))
            End If
        End If

        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sb.ToString)

        If dt Is Nothing Then
            GetInputStepCheckPointList.Result = False
        Else
            GetInputStepCheckPointList.Result = True
            GetInputStepCheckPointList.DBTable = dt
        End If
    End Function
#End Region

    ''' <summary>
    ''' 获取IP
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetIP() As Object

        GetIP = ""

        Dim objWMIService, colAdapters, objAdapter As Object
        Dim strComputer = "."
        objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        If colAdapters.Count > 0 Then
            If UBound(colAdapters.ItemIndex(0).IPAddress) > 0 Then
                GetIP = colAdapters.ItemIndex(0).IPAddress(0)
            End If
        End If

        If String.IsNullOrWhiteSpace(GetIP) Then
            Dim HostIP As IPHostEntry

            '//定义主机IP地址集

            Dim IPAdress As IPAddress

            HostIP = Dns.GetHostByName(Dns.GetHostName())

            '//或取本地主机的IP地址集

            IPAdress = New IPAddress(HostIP.AddressList(0).Address)

            '//或取本地主机的IP地址集

            GetIP = IPAdress.ToString
        End If

    End Function
    ''' <summary>
    ''' 将检测项转化为HTML显示内容
    ''' add:Wangjh 20211111
    ''' </summary>
    ''' <param name="strCheckCode"></param>
    ''' <param name="isUseIp"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ConvertTohtml(ByVal strCheckCode As String, ByVal usingCheckPath As String, ByVal isUseIp As Boolean) As String Implements uLMSStepCheckPointIBusiness.ConvertTohtml
        If isUseIp Then
            usingCheckPath = "http://" + GetIP() + "/" + usingCheckPath.Substring(usingCheckPath.IndexOf("InSiteWebApplication"))
        Else
            usingCheckPath = "\" + usingCheckPath.Substring(usingCheckPath.IndexOf("InSiteWebApplication"))
        End If

        Return DataAdjust.ParseCode2(strCheckCode, usingCheckPath) '用图片路径形式
        'Return DataAdjust.ParseCode3(strCheckCode) '用base64图片形式

    End Function

#Region "检测项导入导出"
    ''' <summary>
    ''' 获取批次工序的检测项
    ''' </summary>
    ''' <param name="workflowstepId"></param>
    ''' <param name="stepInfoID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetContainerCheckPointList(ByVal workflowstepId As String, ByVal stepInfoID As String) As DataTable Implements uLMSStepCheckPointIBusiness.GetContainerCheckPointList
        Dim strSql = <string>
SELECT s.stepcheckpointid,s.checktype,s.checkpointnotedis,s.checkpointnote,s.keycheck,s.drawingrequiredis,s.drawingrequire,
DECODE(s.checktype,'3','设计特性','4','过程参数','其他') checktypename,
DECODE(s.keycheck,'1','是'，'否') keycheckname
 FROM stepcheckpoint s
WHERE s.workflowstepid = '{0}'                        
                     </string>.Value
        strSql = String.Format(strSql, workflowstepId)

        If Not String.IsNullOrWhiteSpace(stepInfoID) Then
            strSql += " and s.stepinfoid = '" + stepInfoID + "'"
        End If

        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 保存导入
    ''' </summary>
    ''' <param name="para"></param>
    ''' <param name="type"></param>
    ''' <param name="msg"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveCheckPointResultByImport(ByVal para As Dictionary(Of String, String), ByVal type As Integer, ByRef msg As String) As Boolean Implements uLMSStepCheckPointIBusiness.SaveCheckPointResultByImport
        Try
            Dim sqlList As New ArrayList
            Dim strSql = <string> SELECT sp.stepcheckpointresultid FROM stepcheckpointresult sp 
WHERE sp.stepcheckpointid = '{0}' AND sp.containerid = '{1}'  </string>.Value

            If type <> 1 Then '如果是二检或者检验，则添加报工验证
                strSql += " and sp.containerstepworkreportid = '" + para("ContainerStepWorkReportID").ToString + "'"
            End If

            strSql = String.Format(strSql, para("StepCheckPointID").ToString, para("ContainerID").ToString)
            If Not String.IsNullOrWhiteSpace(para("ChildContainerID").ToString) Then
                strSql += " AND sp.childcontainerid = '" + para("ChildContainerID").ToString + "'"
            End If
            Dim resDt = DatabaseHelper.Query_ReturnDatTable(strSql)
            If resDt.Rows.Count > 0 Then '如果存在,则添加结果ID，
                para.Add("StepCheckPointResultID", resDt.Rows(0)("stepcheckpointresultid").ToString)
            Else
                If type <> 1 Then
                    para.Add("StepCheckPointResultID", Nothing)
                End If
            End If
            If type = 1 Then '如果是工人录入
                '工人录入验证 add:wangjh 20221206
                strSql = String.Format(<string>select 1 from stepcheckpointresult sc where sc.containerid in ({0}) and sc.checkerid!='{1}' 
and sc.containerstepworkreportid is null </string>.Value, "'" + para("ContainerID") + "'", para("WORKERID"))
                If Not String.IsNullOrWhiteSpace(para("ChildContainerID")) Then
                    strSql += String.Format(" and sc.childcontainerid ='{0}' ", para("ChildContainerID"))
                End If
                If DatabaseHelper.GetSingle(strSql) IsNot Nothing Then
                    msg = "存在其他工人录入检测项但未报工，请等待别人报工完成，或删除别人录入但未报工的检测项"
                    Return False
                End If

                Return SaveCheckResultByWorker(para)
            ElseIf type = 2 Then '如果是二检录入
                Return SaveCheckResultBySecondCheck(para)
            ElseIf type = 3 Then '检验录入
                Return SaveCheckResultByCheck(para)
            End If
            Return False
        Catch ex As Exception
            msg = ex.Message
            Return False
        End Try
    End Function
#End Region

    ''' <summary>
    ''' 批量保存检验实测值 add by zhangrj 2022-10-26
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveBatchCheckResultByCheck(ByVal para As List(Of Dictionary(Of String, String))) As Boolean Implements uLMSStepCheckPointIBusiness.SaveBatchCheckResultByCheck
        Dim strList As New ArrayList
        Dim strsql As New StringBuilder
        For Each dic As Dictionary(Of String, String) In para
            strsql.Clear()
            strsql.AppendLine("UPDATE STEPCHECKPOINTRESULT SET lastchangedate=sysdate,tempdealfail=0,")
            strsql.AppendFormat("CHECKDATE=sysdate,CHECKPOINTRESULTNOTE='{0}', ", dic("CheckPointResultNote"))
            strsql.AppendFormat("CHECKPOINTRESULTNOTEDIS='{0}', ", dic("CheckPointResultNoteDis"))
            strsql.AppendFormat("CheckerID='{0}', ", dic("CheckerID"))
            strsql.AppendFormat("checkresultdocpath='{0}' ", dic("CheckResultDocPath"))
            'strsql.AppendFormat("ContainerStepWorkReportID='{0}' ", para("ContainerStepWorkReportID"))
            strsql.AppendFormat(" where STEPCHECKPOINTRESULTID='{0}'", dic("StepCheckPointResultID"))
            strList.Add(strsql.ToString())
        Next
        DatabaseHelper.ExecuteSqlTran(strList)
        Return True
    End Function

#Region "实测值提取"
    'add by longb 2023-02-26
    ''' <summary>
    ''' 实测值提取
    ''' </summary>
    ''' <param name="content">被提取的内容</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetCheckPointValue(ByVal content As String) As List(Of Dictionary(Of String, String)) Implements uLMSStepCheckPointIBusiness.GetCheckPointValue
        Dim List As New List(Of Dictionary(Of String, String))
        Dim sy As Array = GetSubStrCountInStr(content, "<Image>", 0)
        Dim ey As Array = GetSubStrCountInStr(content, "</Image>", 0)
        For i = 0 To sy.Length - 1
            Dim baseValue As String = String.Empty, upValue = String.Empty, dwValue = String.Empty
            Dim ImageContent As String = content.Substring(sy(i) + 7, ey(i) - (sy(i) + 7)) '截取<Image>里面的内容
            If (ImageContent.Contains("<T")) Then '含有基准值、上下限值情况
                baseValue = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0), "[^\d.\d]", "")
                If ImageContent.Contains("°") Then
                    baseValue = Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0)
                End If
                upValue = Microsoft.VisualBasic.Strings.Split(Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(1), "!")(0).Replace("T", "")
                dwValue = Microsoft.VisualBasic.Strings.Split(Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(1), "!")(1).Replace(">", "")
            End If
            If (ImageContent.Contains("<H")) Then '只含基准值，上限
                baseValue = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0), "[^\d.\d]", "")
                If ImageContent.Contains("°") Then
                    baseValue = Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0)
                End If
                upValue = Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(1).Replace("H>", "").Replace("</H>", "")
            End If

            If (ImageContent.Contains("<L")) Then '只含基准值，下限
                baseValue = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0), "[^\d.\d]", "")
                If ImageContent.Contains("°") Then
                    baseValue = Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(0)
                End If
                dwValue = Microsoft.VisualBasic.Strings.Split(ImageContent, "<")(1).Replace("L>", "").Replace("</L>", "")
            End If


            If (ImageContent.Contains("<R")) Then  '去除材料
                baseValue = ImageContent.Replace("<R>", "").Replace("</R>", "")
            End If

            If (ImageContent.Contains("√")) Then '指定加工方法
                baseValue = Microsoft.VisualBasic.Strings.Split(ImageContent.Replace("<√>", "").Replace("</√>", ""), "<")(0)
                upValue = Microsoft.VisualBasic.Strings.Split(Microsoft.VisualBasic.Strings.Split(ImageContent.Replace("<√>", "").Replace("</√>", ""), "<")(1), ",")(0)
                dwValue = Microsoft.VisualBasic.Strings.Split(Microsoft.VisualBasic.Strings.Split(ImageContent.Replace("<√>", "").Replace("</√>", ""), "<")(1), ",")(1).Replace(">", "")
            End If

            If ImageContent.Contains("<&70><+><&13>") Then
                upValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+><&13>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
                'dwValue = "0"
            End If
         
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&1>") And Not ImageContent.Contains("<&1>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&2>") And Not ImageContent.Contains("<&2>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&3>") And Not ImageContent.Contains("<&3>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&4>") And Not ImageContent.Contains("<&4>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&5>") And Not ImageContent.Contains("<&5>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&9>") And Not ImageContent.Contains("<&9>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&10>") And Not ImageContent.Contains("<&10>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&11>") And Not ImageContent.Contains("<&11>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&12>") And Not ImageContent.Contains("<&12>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            If ImageContent.Contains("<&70><+>") And ImageContent.Contains("<+><&90>") And content.Contains("<&13>") And Not ImageContent.Contains("<&13>") Then
                baseValue = System.Text.RegularExpressions.Regex.Replace(ImageContent.Replace("<&70><+>", "").Replace("<+><&90>", ""), "[^\d.\d]", "")
            End If
            Dim db As Double = 0
            If (Not String.IsNullOrWhiteSpace(baseValue) Or Not String.IsNullOrWhiteSpace(upValue) Or Not String.IsNullOrWhiteSpace(dwValue)) Then
                'If Double.TryParse(baseValue, db) Or Double.TryParse(upValue, db) Or Double.TryParse(dwValue, db) Then
                Dim dic As New Dictionary(Of String, String)
                dic.Add("baseValue", baseValue.Replace("'", "''"))
                dic.Add("upValue", upValue.Replace("'", "''"))
                dic.Add("dwValue", dwValue.Replace("'", "''"))
                List.Add(dic)
                'End If
            End If
        Next
        If sy.Length = 0 Then
            If content.Contains("Φ") And content.Contains("JS8") Then '公差提取
                Dim baseValue As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "JS8")(0), "[^\d.\d]", "")
                Dim value As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "JS8")(1), "[^\d.\d]", "")
                Dim dic As New Dictionary(Of String, String)
                dic.Add("baseValue", baseValue.Replace("'", "''"))
                dic.Add("upValue", value.Replace("'", "''"))
                dic.Add("dwValue", value.Replace("'", "''"))
                List.Add(dic)
            ElseIf content.Contains("Φ") And content.Contains("±") Then
                Dim baseValue As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "±")(0), "[^\d.\d]", "")
                Dim value As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "±")(1), "[^\d.\d]", "")
                Dim dic As New Dictionary(Of String, String)
                dic.Add("baseValue", baseValue.Replace("'", "''"))
                dic.Add("upValue", "+" + value.Replace("'", "''"))
                dic.Add("dwValue", "-" + value.Replace("'", "''"))
                List.Add(dic)
            ElseIf content.Contains("±") And Regex.Matches(content, "±").Count.Equals(1) Then
                Dim baseValue As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "±")(0), "[^\d.\d]", "")
                Dim value As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "±")(1), "[^\d.\d]", "")
                Dim dic As New Dictionary(Of String, String)
                dic.Add("baseValue", baseValue.Replace("'", "''"))
                dic.Add("upValue", "+" + value.Replace("'", "''"))
                dic.Add("dwValue", "-" + value.Replace("'", "''"))
                List.Add(dic)
            ElseIf content.Contains("~") And Regex.Matches(content, "~").Count.Equals(1) Then
                Dim upValue As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "~")(0), "[^\d.\d]", "")
                Dim dwValue As String = System.Text.RegularExpressions.Regex.Replace(Microsoft.VisualBasic.Strings.Split(content, "~")(1), "[^\d.\d]", "")
                Dim dic As New Dictionary(Of String, String)
                dic.Add("baseValue", "")
                dic.Add("upValue", upValue.Replace("'", "''"))
                dic.Add("dwValue", dwValue.Replace("'", "''"))
                List.Add(dic)
            Else
                Dim baseValue As String = System.Text.RegularExpressions.Regex.Replace(content, "[^\d.\d]", "")
                Dim dic As New Dictionary(Of String, String)
                If Not String.IsNullOrWhiteSpace(baseValue) Then
                    dic.Add("baseValue", baseValue.Replace("'", "''"))
                Else
                    dic.Add("baseValue", content.Replace("'", "''"))
                End If
                dic.Add("upValue", "")
                dic.Add("dwValue", "")
                List.Add(dic)
            End If
        End If
        If List.Count = 0 Then
            Dim dic As New Dictionary(Of String, String)
            dic.Add("baseValue", content.Replace("'", "''"))
            dic.Add("upValue", "")
            dic.Add("dwValue", "")
            List.Add(dic)
        End If
        Return List
    End Function
    ''' <summary>
    ''' 返回特殊字符在字符串串中的位置
    ''' </summary>
    ''' <param name="str">字符串</param>
    ''' <param name="substr">特殊字符</param>
    ''' <param name="StartPos">开始位置</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSubStrCountInStr(ByVal str As String, ByVal substr As String, ByVal StartPos As Integer) As Array
        Dim foundPos As Integer = -1
        Dim count As Integer = 0
        Dim foundItems As New List(Of Integer)
        Do
            foundPos = str.IndexOf(substr, StartPos)
            If (foundPos > -1) Then
                StartPos = foundPos + 1
                count = count + 1
                foundItems.Add(foundPos)
            End If
        Loop While (foundPos > -1 And StartPos < str.Length)
        Return foundItems.ToArray()
    End Function
    ''' <summary>
    ''' 根据检测项ids 更新基准值，上公差，下公差
    ''' </summary>
    ''' <param name="listPara">stepCheckPointId 集合</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateStepCheckPointValue(ByVal listPara As List(Of Dictionary(Of String, Object))) As Boolean Implements uLMSStepCheckPointIBusiness.UpdateStepCheckPointValue
        Dim arrList As New ArrayList
        Dim selectSQL As String = <string>SELECT s.DrawingRequire FROM STEPCHECKPOINT s WHERE s.STEPCHECKPOINTID ='{0}'</string>
        Dim updateSQL As String = <string>UPDATE STEPCHECKPOINT s SET s.BASEVALUE ='{0}',s.CEILFLOAT ='{1}',s.FLOORFLOAT ='{2}' WHERE s.STEPCHECKPOINTID ='{3}'</string>
        For Each para In listPara
            Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(selectSQL, para("stepCheckPointId")))
            If dt.Rows.Count > 0 Then
                Dim list As List(Of Dictionary(Of String, String)) = GetCheckPointValue(dt.Rows(0)("DrawingRequire"))
                If list.Count > 0 Then
                    arrList.Add(String.Format(updateSQL, list(0)("baseValue"), list(0)("dwValue"), list(0)("upValue"), para("stepCheckPointId")))
                End If
            End If
        Next
        Return DatabaseHelper.ExecuteSqlListTran(arrList)
    End Function
#End Region

#Region "SPC异常规则判定 add by zhangrj 2023-02-23"

    ''' <summary>
    ''' 规则判定
    ''' </summary>
    ''' <param name="checkPointResultID">当前检测项录入结果ID</param>
    ''' <remarks></remarks>
    Public Sub SaveStepCheckPointSPCMonitor(ByVal checkPointResultID As String)
        Try
            Dim strSql = <string>
SELECT sp.basevalue,sp.ceilfloat,sp.floorfloat,sp.spcrule,sp.spctype,sp.checkno,
sp.checkpointnotedis,sp.checkpointnote,sp.drawingrequiredis,sp.drawingrequire,
spr1.workcheckpointresultnotedis,spr1.workcheckpointresultnote,
spr1.checkpointresultnotedis,spr1.checkpointresultnote,spr1.stepcheckpointresultid
FROM  stepcheckpointresult spr
LEFT JOIN stepcheckpoint sp ON sp.stepcheckpointid = spr.stepcheckpointid
LEFT JOIN stepcheckpointresult spr1 ON spr1.stepcheckpointid = sp.stepcheckpointid
WHERE spr.stepcheckpointresultid = '{0}' AND sp.isspc = 1
ORDER BY spr1.createdate DESC                   
                    </string>.Value
            strSql = String.Format(strSql, checkPointResultID)
            Dim dtCheckPoint = DatabaseHelper.Query_ReturnDatTable(strSql)
            If dtCheckPoint.Rows.Count = 0 Then
                Exit Sub
            End If
            '筛选数据，使当前结果值放在第一位
            For Each dr As DataRow In dtCheckPoint.Rows
                If dr("stepcheckpointresultid").ToString() = checkPointResultID Then
                    Exit For
                End If
                dr.Delete()
            Next
            dtCheckPoint.AcceptChanges()
            Dim checkSPCStatus = False 'SPC状态（0：正常，1：异常）
            Dim spcRule = dtCheckPoint.Rows(0)("spcrule").ToString() '判异规则
            Dim rules = spcRule.Split(",")
            For Each rule As String In rules
                Select Case rule
                    Case "R0" '超出规格限制
                        checkSPCStatus = IsSPCRuleForR0(dtCheckPoint)
                    Case "R1" '连续9个点落在目标值的同一侧（上或下）
                        checkSPCStatus = IsSPCRuleForR1(dtCheckPoint)
                    Case "R2" '连续6个点递增或递减
                        checkSPCStatus = IsSPCRuleForR2(dtCheckPoint)
                    Case "R3" '连续14点中相临点交替上下
                        checkSPCStatus = IsSPCRuleForR3(dtCheckPoint)
                End Select
                '如果存在一个异常，则结束
                If checkSPCStatus Then
                    Exit For
                End If
            Next
            '更新是否异常
            strSql = String.Format("UPDATE stepcheckpointresult sp SET sp.spcstatus = {0} WHERE sp.stepcheckpointresultid = '{1}'", IIf(checkSPCStatus, 1, 0), checkPointResultID)
            DatabaseHelper.ExecuteSql(strSql)
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

    ''' <summary>
    ''' R0规则判定（超出规格限制）
    ''' </summary>
    ''' <param name="dtCheckResult"></param>
    ''' <param name="drResult"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function IsSPCRuleForR0(ByVal dtCheckResult As DataTable) As Boolean
        IsSPCRuleForR0 = False
        Dim res = GetSpcBaseValue(dtCheckResult.Rows(0))
        Dim baseValue = res.Item1, floorFloat = res.Item2, ceilFloat = res.Item3  '基本值，上浮动，下浮动
        Dim targetValue = baseValue + Math.Round((floorFloat + ceilFloat) / 2, 3) '目标值（保留三位小数）
        Dim currTargetValue = 0 '当前录入值的目标值
        If Not GetResultTargetValue(dtCheckResult.Rows(0)("workcheckpointresultnote").ToString(), currTargetValue) Then
            Exit Function
        End If
        '规则判定
        Dim spcType = dtCheckResult.Rows(0)("spctype").ToString()
        If spcType = "1" Then '计数型（超出上下限值）
            If currTargetValue < (baseValue + ceilFloat) Or currTargetValue > (baseValue + floorFloat) Then '如果录入目标值小于下限值，则异常
                IsSPCRuleForR0 = True
            End If
        ElseIf spcType = "2" Then '计量型（与目标值不同）
            If currTargetValue <> targetValue Then
                IsSPCRuleForR0 = True
            End If
        End If
    End Function

    ''' <summary>
    ''' R1规则判定（连续9个点落在目标值的同一侧（上或下））
    ''' </summary>
    ''' <param name="dtCheckResult"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function IsSPCRuleForR1(ByVal dtCheckResult As DataTable) As Boolean
        Dim res = False
        Dim resT = GetSpcBaseValue(dtCheckResult.Rows(0))
        Dim baseValue = resT.Item1, floorFloat = resT.Item2, ceilFloat = resT.Item3  '基本值，上浮动，下浮动
        Dim targetValue = baseValue + Math.Round((floorFloat + ceilFloat) / 2, 3) '目标值（保留三位小数）
        If dtCheckResult.Rows.Count >= 9 Then
            Dim iMark = 0 '总标识（-1：下侧，1：上侧）
            Dim iCount = 0 '连续在同一侧的数量
            '循环计算
            For Each dr As DataRow In dtCheckResult.Rows
                Dim currTargetValue = 0 '当前结果值的目标值
                Dim currIMark = 0 '当前结果值的标识
                If Not GetResultTargetValue(dr("workcheckpointresultnote").ToString(), currTargetValue) Then
                    Exit For
                End If
                '判断当前值的标识
                If currTargetValue > targetValue Then '如果是大于目标值
                    currIMark = 1
                ElseIf currTargetValue < targetValue Then '如果是小于目标值                
                    currIMark = -1
                Else '等于目标值，则退出
                    Exit For
                End If
                '计算出是否连续
                If iCount = 0 Then '如果是第一个，则总标识等于第一个值的标识
                    iMark = currIMark
                Else
                    If iMark <> currIMark Then
                        Exit For
                    End If
                End If
                iCount = iCount + 1
                '如果同侧存在9次，结束
                If iCount = 9 Then
                    res = True
                    Exit For
                End If
            Next
        End If
        Return res
    End Function

    ''' <summary>
    ''' R2规则判定（连续6个点递增或递减）
    ''' </summary>
    ''' <param name="dtCheckResult"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function IsSPCRuleForR2(ByVal dtCheckResult As DataTable) As Boolean
        Dim res = False
        If dtCheckResult.Rows.Count >= 6 Then
            Dim itemValue = 0 '递增递减固定值
            Dim iCount = 1 '连续递增或递减计数（必须连续）
            For index = 0 To dtCheckResult.Rows.Count - 2
                Dim currTargetValue = 0, nextTargetValue = 0
                If Not GetResultTargetValue(dtCheckResult.Rows(index + 1)("workcheckpointresultnote").ToString(), nextTargetValue) Then
                    Exit For
                End If
                If Not GetResultTargetValue(dtCheckResult.Rows(index)("workcheckpointresultnote").ToString(), currTargetValue) Then
                    Exit For
                End If
                Dim currItemValue = nextTargetValue - currTargetValue '两个前后值相减
                If currItemValue = 0 Then '如果当前相差值为0，则跳出
                    Exit For
                ElseIf index <> 0 And currItemValue <> itemValue Then '如果与固定值不等，则退出
                    Exit For
                Else '递增、递减，计数加1
                    iCount = iCount + 1
                End If
                itemValue = currItemValue '固定值改为当前值（无论是否连续递增、递减）
                '如果存在连续6个递增或递减，结束
                If iCount = 6 Then
                    res = True
                    Exit For
                End If
            Next
        End If
        Return res
    End Function

    ''' <summary>
    ''' R3规则判定（连续14点中相临点交替上下）
    ''' </summary>
    ''' <param name="dtCheckResult"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function IsSPCRuleForR3(ByVal dtCheckResult As DataTable) As Boolean
        Dim res = False
        If dtCheckResult.Rows.Count >= 14 Then
            Dim resT = GetSpcBaseValue(dtCheckResult.Rows(0))
            Dim baseValue = resT.Item1, floorFloat = resT.Item2, ceilFloat = resT.Item3  '基本值，上浮动，下浮动
            Dim targetValue = baseValue + Math.Round((floorFloat + ceilFloat) / 2, 3) '目标值（保留三位小数）
            Dim itemValue = 0 '上下交替值（1：上，-1：下）
            Dim iCount = 0 '连续上下交替计数（必须连续）
            For index = 0 To dtCheckResult.Rows.Count - 1
                Dim currTargetValue = 0 '当前值得目标值
                Dim currItemValue = 0 '当前值的上下交替值
                If Not (GetResultTargetValue(dtCheckResult.Rows(index)("workcheckpointresultnote").ToString(), currTargetValue)) Then
                    Exit For
                End If
                '如果目标值都相等，则退出
                If currTargetValue = targetValue Then
                    Exit For
                ElseIf currTargetValue > targetValue Then
                    currItemValue = 1
                Else
                    currItemValue = -1
                End If
                '如果与前一个相等则退出
                If itemValue = currItemValue Then
                    Exit For
                End If
                itemValue = currItemValue
                iCount = iCount + 1
                '如果存在连续14个点交替上下，结束
                If iCount = 14 Then
                    res = True
                    Exit For
                End If
            Next
        End If
        Return res
    End Function

    ''' <summary>
    ''' 获取检测项基本SPC数值信息
    ''' </summary>
    ''' <param name="drCheck"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSpcBaseValue(ByVal drCheck As DataRow) As Tuple(Of Double, Double, Double)
        Dim baseValue As Double = 0, ceilFloat As Double = 0, floorFloat As Double = 0 '基本值，下浮动，上浮动
        If String.IsNullOrWhiteSpace(drCheck("basevalue").ToString()) Then '如果等于空，则取要求值
            Dim note = GetCheckPointValue(drCheck("checkpointnote").ToString().Trim())
            If note.Count > 0 Then
                If Not Double.TryParse(note(0)("baseValue"), baseValue) Then
                    Return New Tuple(Of Double, Double, Double)(0, 0, 0)
                    Exit Function
                End If
                If Not Double.TryParse(note(0)("upValue"), floorFloat) Then
                    Return New Tuple(Of Double, Double, Double)(baseValue, 0, 0)
                    Exit Function
                End If
                If Not Double.TryParse(note(0)("dwValue"), ceilFloat) Then
                    Return New Tuple(Of Double, Double, Double)(baseValue, floorFloat, 0)
                    Exit Function
                End If
            End If
        Else
            baseValue = Double.Parse(drCheck("basevalue").ToString().Trim())
            If Not String.IsNullOrWhiteSpace(drCheck("ceilfloat").ToString()) Then
                ceilFloat = Double.Parse(drCheck("ceilfloat").ToString().Trim())
            End If
            If Not String.IsNullOrWhiteSpace(drCheck("floorfloat").ToString()) Then
                floorFloat = Double.Parse(drCheck("floorfloat").ToString().Trim())
            End If
        End If
        Return New Tuple(Of Double, Double, Double)(baseValue, floorFloat, ceilFloat)
    End Function

    ''' <summary>
    ''' 获取录入值的目标值
    ''' </summary>
    ''' <param name="resultNote"></param>
    ''' <param name="targetValue"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetResultTargetValue(ByVal resultNote As String, ByRef targetValue As Double) As Boolean
        GetResultTargetValue = False
        Dim dic = GetCheckPointValue(resultNote.Trim())(0) '获取实测值
        Dim currBaseValue As Double = 0, upValue As Double = 0, dwValue As Double = 0 '录入值的基本值、上浮动、下浮动
        If Not Double.TryParse(dic("baseValue"), currBaseValue) Then
            Exit Function
        End If
        If Not String.IsNullOrWhiteSpace(dic("upValue")) Then
            If Not Double.TryParse(dic("upValue"), upValue) Then
                Exit Function
            End If
        End If
        If Not String.IsNullOrWhiteSpace(dic("dwValue")) Then
            If Not Double.TryParse(dic("dwValue"), dwValue) Then
                Exit Function
            End If
        End If
        targetValue = currBaseValue + Math.Round((upValue + dwValue) / 2, 3) '当前录入值的目标值
        GetResultTargetValue = True
    End Function

#End Region

#Region "SPC异常失控预警 add by zhangrj 2023-02-28"
    ''' <summary>
    ''' 获取SPC异常失控预警数据
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetStepCheckPointSpcWarningData(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uLMSStepCheckPointIBusiness.GetStepCheckPointSpcWarningData
        Dim sql = <string>
SELECT pb.productname||':'||p.productrevision AS productnameAndrev,wb.workflowname||':'||w.workflowrevision workflownameAndrev,
s.specno,s.opdesc,c.containername,cci.containerno,e.fullname workername,sp.spcrule,spr.stepcheckpointresultid,sci.spcstepcheckitemdealid,
spr.lastchangedate,sci.dealdate,sci.examinedate,em.fullname auditor,emc.fullname dealName,
CASE WHEN sci.spcstepcheckitemdealid IS NULL THEN '待处理' WHEN sci.status = 1 THEN '已驳回' WHEN sci.status = 2 THEN '待审核' ELSE '已处理' END spcwarnname
FROM stepcheckpoint sp
LEFT JOIN stepcheckpointresult spr ON spr.stepcheckpointid = sp.stepcheckpointid
LEFT JOIN employee e ON e.employeeid = spr.workerid
LEFT JOIN  SpcStepCheckItemDeal sci ON sci.stepcheckpointresultid = spr.stepcheckpointresultid AND sci.isuse = 0
LEFT JOIN employee emc ON emc.employeeid = sci.createempid
LEFT JOIN employee em ON em.employeeid = sci.auditor
LEFT JOIN product p ON p.productid = sp.productid
LEFT JOIN productbase pb ON pb.productbaseid = p.productbaseid
LEFT JOIN workflowstep ws ON ws.workflowstepid = sp.workflowstepid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid,ws.specid)
LEFT JOIN container c ON c.containerid = spr.containerid
LEFT JOIN containercurrentinfo cci ON cci.containerid = c.containerid
LEFT JOIN Workflow w ON w.workflowid = DECODE(cci.isinstore,-1,c.mfgworkflowid,0,cci.workflowid,1,cci.bsworkflowid)
LEFT JOIN workflowbase wb ON wb.workflowbaseid = w.workflowbaseid
 WHERE spr.spcstatus = 1 And sp.isspc = 1
                  </string>.Value
        sql = String.Format(sql, "<=")
        Dim page As New uMESPagingDataDTO

        'If Not String.IsNullOrWhiteSpace(para("ProductID")) Then
        '    sql += String.Format(" and p.productid = '{0}'", para("ProductID"))
        'End If

        If Not String.IsNullOrWhiteSpace(para("WorkflowID")) Then
            sql += String.Format(" and w.workflowid = '{0}'", para("WorkflowID"))
        End If

        If Not String.IsNullOrWhiteSpace(para("SpecNo")) Then
            sql += String.Format(" and s.specno = '{0}'", para("SpecNo"))
        End If

        If Not String.IsNullOrWhiteSpace(para("WarningTime")) Then
            sql += String.Format(" AND to_char(spr.lastchangedate,'YYYY-MM-DD') = '{0}'", para("WarningTime"))
        End If

        If Not String.IsNullOrWhiteSpace(para("DealTime")) Then
            sql += String.Format(" AND to_char(sci.dealdate,'YYYY-MM-DD') = '{0}'", para("DealTime"))
        End If

        If Not String.IsNullOrWhiteSpace(para("ExamineTime")) Then
            sql += String.Format(" AND to_char(sci.examinedate,'YYYY-MM-DD') = '{0}'", para("ExamineTime"))
        End If

        If Not String.IsNullOrWhiteSpace(para("dealName")) Then
            sql += String.Format(" AND (emc.fullname like '{0}%' or emc.employeename like '{0}%')", para("dealName"))
        End If

        If Not String.IsNullOrWhiteSpace(para("examineName")) Then
            sql += String.Format(" AND (em.fullname like '{0}%' or em.employeename like '{0}%')", para("examineName"))
        End If

        page.PageSize = Integer.Parse(para("PageSize"))
        page.CurrentPageIndex = Integer.Parse(para("PageIndex"))
        page.strSQL = sql
        Return DatabaseHelper.RunProcedureForPage(page)
    End Function
#End Region
End Class